﻿using System;
using System.Diagnostics;
using NUnit.Framework;
using octalforty.Componento.ComponentModel.Tracing;
using Rhino.Mocks;
using Trace=System.Diagnostics.Trace;

namespace octalforty.Componento.Tests.Componento.ComponentModel.Tracing
{
    [TestFixture()]
    public class TraceTraceWriterTestFixture
    {
        [SetUp()]
        public void SetUp()
        {
            Trace.Listeners.Clear();
        }

        [TearDown()]
        public void TearDown()
        {
            Trace.Listeners.Clear();
        }

        [Test()]
        public void Write()
        {
            var mockRepository = new MockRepository();
            var traceListener = mockRepository.StrictMock<TraceListener>();

            using(mockRepository.Record())
            {
                Expect.Call(traceListener.IndentSize = 4);
                Expect.Call(traceListener.IndentLevel = 0);
                Expect.Call(() => traceListener.WriteLine("2009-09-16 12:09:56.000: -      Foo -   Error - Message 1"));
                Expect.Call(() => traceListener.WriteLine("2009-09-16 12:09:56.000: -      Bar -    Info -     Message 2"));
                Expect.Call(() => traceListener.WriteLine("2009-09-16 12:09:56.000: -      Baz - Warning -         Message 3"));
            } // using

            Trace.Listeners.Add(traceListener);

            var traceWriter = new TraceTraceWriter();
            var dateTime = new DateTime(2009, 9, 16, 12, 34, 56);

            traceWriter.Write(dateTime, TraceLevel.Error, 0, "Foo", "Message 1");
            traceWriter.Write(dateTime, TraceLevel.Info, 1, "Bar", "Message 2");
            traceWriter.Write(dateTime, TraceLevel.Warning, 2, "Baz", "Message 3");
        }
    }
}
